#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
const int N = 2e5 + 10;
string s;
int n, k;
int main()
{
	while (cin >> k >> s) {
		map<char, int>mp;
		int ans = 0;
		bool flag = 0;
		int l, r;
		for (l = 0, r = 0; r < s.size(); r++) {
			mp[s[r]]++;
			if (mp[s[r]] <= k)continue;
			flag = 1;
			//cout << "l==" << l << "  r==" << r << endl;
			ans = max(r - l, ans);
			while (s[l] != s[r]) {
				mp[s[l]]--;
				l++;
			}
			mp[s[l]]--;
			l++;
		}
		ans = max(ans, r - l);
		if (!flag)cout << s.size() << endl;
		else cout << ans << endl;
	}
	return 0;
}
